package com.company.card_service.api;

import com.company.card_service.model.CompanyCaseType;
import com.company.card_service.model.PassageView;
import com.company.card_service.service.CompanyCaseTypeService;
import com.company.card_service.service.PassageViewService;
import com.company.card_service.vo.CompanyTypeVo;
import com.company.card_service.vo.PassageAndView;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 唐琪
 * @Date 2022/9/17 15:32
 * @Version 1.0
 */
@Api("小程序公司案例信息")
@RestController
@RequestMapping("api/company/caseType")
public class ApiCompanyCaseTypeController {

    @Autowired
    private CompanyCaseTypeService companyCaseTypeService;

    @Autowired
    private PassageViewService passageViewService;

    @GetMapping("getCompanyTypeAndPassage/{id}")
    @ApiOperation("获取公司案例类型和发布的文章")
    public Result getCompanyTypeAndPassage (@PathVariable Integer id){
        List<CompanyTypeVo> allDataOfCompanyTypeAndPassage = companyCaseTypeService.getAllDataOfCompanyTypeAndPassage(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),allDataOfCompanyTypeAndPassage);
    }

    @GetMapping("getPassageDetails/{id}")
    @ApiOperation("文章详情")
    public Result getPassageDetails (@PathVariable Integer id){
        PassageAndView passageDetails = companyCaseTypeService.getPassageDetails(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),passageDetails);
    }

    @PostMapping("addPassageView")
    @ApiOperation("增加访问文章记录")
    public Result addPassageView(@RequestBody PassageView passageView){
        Boolean save =  passageViewService.savePassageView(passageView);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),save);
    }

    @GetMapping("getCompanyType/{id}")
    @ApiOperation("获取公司案例类型(备选方案二)")
    public Result getCompanyType (
            @ApiParam(name = "id", value = "员工id", required = true)
            @PathVariable Integer id){
        List<CompanyCaseType> companyCaseTypes = companyCaseTypeService.getCompanyType(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),companyCaseTypes);
    }

    @GetMapping("getPassageByTypeId/{id}")
    @ApiOperation("获取公司案例下的文章(备选方案二)")
    public Result getPassageByTypeId (
            @ApiParam(name = "id", value = "案例类型id", required = true)
            @PathVariable Integer id){
        List<PassageAndView> passageAndViewList =  companyCaseTypeService.getPassageByTypeId(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),passageAndViewList);
    }

    @GetMapping("getPassageDetail/{id}")
    @ApiOperation("文章详情(备案方案二)")
    public Result getPassageDetail (
            @ApiParam(name = "id", value = "文章id", required = true)
            @PathVariable Integer id){
        PassageAndView passageDetails = companyCaseTypeService.getPassageDetail(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),passageDetails);
    }
}
